//
//  YSMacro.h
//  YSKitExample
//
//  Created by Kyson on 2017/6/16.
//  Copyright © 2017年 YangShen. All rights reserved.
//

#ifndef YSMacro_h
#define YSMacro_h

#ifdef DEBUG
#define NSLog(FORMAT, ...) do {fprintf(stderr,"🐶%s:%d %s🐱  %s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[[NSString stringWithUTF8String:__PRETTY_FUNCTION__] lastPathComponent] UTF8String], [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);} while(0)
#else
#define NSLog(...)
#endif

// 写入一个Plist文件，一般用来查看网络请求返回数据，这样做可以规范看到里面内容
#define YSSaveDesktopPlist(response) [response writeToFile:@"/Users/shen/Desktop/test.plist" atomically:YES];

//------------------------------ABOUT 缩写 --------------------------------
#define kApplication        [UIApplication sharedApplication]
#define kKeyWindow          [UIApplication sharedApplication].keyWindow
#define kAppDelegate        [UIApplication sharedApplication].delegate
#define kUserDefaults       [NSUserDefaults standardUserDefaults]
#define kNotificationCenter [NSNotificationCenter defaultCenter]

//----------------------ABOUT SCREEN & SIZE 屏幕&尺寸 ----------------------------
/**
 iPad Air           {{0, 0}, {768, 1024}}
 iphone4s           {{0, 0}, {320, 480}}      960*640
 iphone5 5s         {{0, 0}, {320, 568}}      1136*640
 iphone6 6s         {{0, 0}, {375, 667}}      1334*750
 iphone6Plus 6sPlus {{0, 0}, {414, 736}}      1920*1080
 Apple Watch 1.65inches(英寸) 320*640
 */
#define kScreenWidth  ([[UIScreen mainScreen] bounds].size.width)
#define kScreenHeight ([[UIScreen mainScreen] bounds].size.height)
#define kNavigationBarHeightIOS7 64.0f
#define KNavigationBarHeightIOS6 44.0f
#define kStatusBarH     20.0f
#define kTabBarHeight   49.0f
#define kKeyboardHeight 216
#define kContentHeight (kScreenHeight-64-KTabBarHeight)
#define kOriginalContentHeight (kScreenHeight-64)
#define kScreenWPoint (float)kScreenWidth/320.f
#define kScreenHPoint (float)kScreenHeight/480.f
#define kLineH         (1 / [UIScreen mainScreen].scale)


#pragma mark -- 设备类型
//判断是否 Retina屏、设备是否iPhone 5、是否是iPad
#define kIsRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)

/** 判断是否为iPhone */
#define kIsiPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

/** 判断是否是iPad */
#define kIsiPad (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

/** 判断是否为iPod */
#define kIsiPod ([[[UIDevice currentDevice] model] isEqualToString:@"iPod touch"])

/** 设备是否为iPhone 4/4S 分辨率320x480，像素640x960，@2x */
#define kiPhone4     ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
/** 设备是否为iPhone 5C/5/5S 分辨率320x568，像素640x1136，@2x */
#define kiPhone5     ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)
/** 设备是否为iPhone 6 分辨率375x667，像素750x1334，@2x */
#define kiPhone6     ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(750, 1334), [[UIScreen mainScreen] currentMode].size) : NO)
/** 设备是否为iPhone 6 Plus 分辨率414x736，像素1242x2208，@3x */
#define kiPhone6Plus ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2208), [[UIScreen mainScreen] currentMode].size) : NO)


//----------------------ABOUT SYSTYM & VERSION 系统与版本
#define kCurrentSystemVersion ([[UIDevice currentDevice] systemVersion])
#define kCurrentSystemVersionNumber [[[UIDevice currentDevice] systemVersion] floatValue]
#define kCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])

#define kIOS7_OR_LATER   ([[[UIDevice currentDevice] systemVersion] compare:@"7.0"] != NSOrderedAscending)
#define kIOS8_OR_LATER   ([[[UIDevice currentDevice] systemVersion] compare:@"8.0"] != NSOrderedAscending)
#define kIOS9_OR_LATER   ([[[UIDevice currentDevice] systemVersion] compare:@"9.0"] != NSOrderedAscending)

// APP版本号
#define kAppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

// 真机 Or 模拟器
#if TARGET_OS_IPHONE
//真机
#endif
#if TARGET_IPHONE_SIMULATOR
//模拟器
#endif


//----------------------ABOUT 空 nil NULL 相关 ----------------------------
// 字符串
#define kStringIsEmpty(str) ((!str || [str isKindOfClass:[NSNull class]] || str.length < 1) ? YES : NO)
// 数组
#define kArrayIsEmpty(arr)  ((!arr || [arr isKindOfClass:[NSNull class]] || arr.count == 0) ? YES : NO)
// 对象
#define kObjectIsEmpty(obj) ((!obj || [obj isKindOfClass:[NSNull class]] \
|| ([obj respondsToSelector:@selector(length)] && [(NSData *)obj length] == 0) \
|| ([obj respondsToSelector:@selector(count)] && [(NSArray *)obj count] == 0)) ? YES : NO)


//----------------------ABOUT GCD 相关 ----------------------------
#define YSGlobal(block) dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block)
#define YSMAIN(block) dispatch_async(dispatch_get_main_queue(),block)

//----------------------ABOUT HELP 相关 ----------------------------
// 过期提醒
#define YSDeprecated(instead) NS_DEPRECATED(2_0, 2_0, 2_0, 2_0, instead)

// 弧度&角度互转
#define kDegreesToRadian(x) (M_PI * (x) / 180.0)
#define kRadianToDegrees(radian) (radian*180.0)/(M_PI)

//获取图片资源
#define kLoadImage(file,ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]pathForResource:file ofType:ext]]
#define kGetImage(imageName) [UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]]

// 沙盒路径
/// Document
#define kDocumentPath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
/// temp
#define kTempPath NSTemporaryDirectory()
/// cache
#define kCachePath [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]

// 弱引用&强引用
#define kWeakSelf(type)   __weak typeof(type) weak##type = type;
#define kStrongSelf(type) __strong typeof(type) type = weak##type;

// 获取一段时间间隔
#define kStartTime CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();
#define kEndTime   NSLog(@"Time: %f", CFAbsoluteTimeGetCurrent() - start)

// TEST
// 使用 ARC 和 MRC
#if __has_feature(objc_arc)
// ARC
#else
// MRC
#endif

//----------------------ABOUT COLOR 颜色相关 ----------------------------
#pragma mark -- Color
#define RGB(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
#define RGBA(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]
// rgb颜色转换（16进制->10进制）
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

#define kClearColor [UIColor clearColor]

#endif /* YSMacro_h */
